package servlet;

import model.Book;
import service.BookService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AddBook_Servlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置 请求和响应的 编码字符为"utf-8"
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String name = req.getParameter("bk_name");
        String price = req.getParameter("bk_price");
        String isbn =  req.getParameter("bk_isbn");
        int id = Integer.parseInt(req.getParameter("bk_id"));
        String lables = req.getParameter("bk_lables");
        String a_name = req.getParameter("bk_a_name");
        String sales = req.getParameter("bk_sales");
        String introduction = req.getParameter("bk_introduction");
        String nums = req.getParameter("bk_nums");
        String Public =  req.getParameter("bk_public");
//      声明一个Book Bean 对象 将各字段存储在对象中
        Book book = new Book(name,price,isbn,id,lables,a_name,sales,introduction,nums,Public);
        BookService bookService = new BookService();
        boolean result =  bookService.AddBookInformation(book);
        System.out.println(result+":"+name+":"+book.getBk_name());
        if(result) {
            System.out.println("chenggong！");
        }else{
//            System.out.println("失败！");
            System.out.println(result+":"+name+":"+book.getBk_name());
        }
        resp.sendRedirect("main/bookinfo.jsp");
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req,resp);

    }
}
